Skip to main content

Traits

MetadataViews.Traits

Traits MetadataView returns the traits associated with a NFT.

import UFC_NFT from 0xUFCNFTADDRESS
import MetadataViews from 0xMETADATAVIEWSADDRESS

pub fun main(address: Address, id: UInt64): MetadataViews.Traits {
let account = getAccount(address)

let collectionRef = account.getCapability(UFC_NFT.CollectionPublicPath)
.borrow<&{UFC_NFT.MomentNFTCollectionPublic}>()
?? panic("Could not borrow capability from public collection")

let nft = collectionRef.borrowMomentNFT(id: id)
?? panic("Couldn't borrow momentNFT")

return nft.resolveView(Type<MetadataViews.Traits>())! as! MetadataViews.Traits
}